<template>
  <div>

  </div>
</template>

<script>
import {mapState, mapMutations} from 'vuex'
import {api} from '@/api'


export default {
  name: 'Common',
  data () {
    return {
    }
  },
  beforeCreate(){
    if(!this.$route.query.token){
      console.log(process.env.USER_TYPE_SYSTEM)
        window.location.href = `${process.env.USER_TYPE_SYSTEM}#/login`
    }
  },
  created () {
    this.$db.clear()
    if(this.$route.query && this.$route.query.token){
      this.$api.auth.commonGetUser(this.$route.query.token).then(r => {
        let data = r.data
        this.saveLoginData(data)
        if(r.data.virtual){
          this.$db.save('virtual',true)
          this.$router.options.routes = this.overseasRouter
          this.$router.push('/overseas/teacherView')
          setTimeout(()=>{
            location.reload()
          },50)
        }else{
          this.$router.push('/')
        }

      })
    }else{
      this.$db.clear()
      this.$router.options.routes = []
    }
    
  },
  methods: {
    ...mapMutations({
      setToken: 'account/setToken',
      setExpireTime: 'account/setExpireTime',
      setUser: 'account/setUser',
      setTheme: 'setting/setTheme',
      setLayout: 'setting/setLayout',
      setMultipage: 'setting/setMultipage',
      fixSiderbar: 'setting/fixSiderbar',
      fixHeader: 'setting/fixHeader',
      setColor: 'setting/setColor'
    }),
    saveLoginData (data) {
      this.setToken(data.token)
      this.setExpireTime(data.exipreTime)
      this.setUser(data.user)
      this.setTheme(data.config.theme)
      this.setLayout(data.config.layout)
      this.setMultipage(data.config.multiPage === '1')
      this.fixSiderbar(data.config.fixSiderbar === '1')
      this.fixHeader(data.config.fixHeader === '1')
      this.setColor(data.config.color)
    }
  }
}
</script>
